
Program hedline;

{$H+}

Uses StrUtils;

Const 
    AppName =   'hedline';
    AppVersion =   '0.1.0';

Var 
    FlagShowUsage, FlagShowVersion:   Boolean;
    FileName:   String;
Procedure ParseParam;

Var 
    P1:   String;
Begin
    If ParamCount = 0 Then
        FlagShowUsage := True
    Else
        Begin
            P1 := ParamStr(1);
            If AnsiStartsStr('-', P1) Then
                Begin
                    P1 := LowerCase(P1);
                    FlagShowUsage := (P1 = '-h') Or (P1 = '--help');
                    FlagShowVersion := (P1 = '-version') Or (P1 = '--version');
                End
            Else
                FileName := P1;
        End;
End;
Procedure ShowUsage;
Begin
    Writeln('Usage: ' + AppName + ' <file name>');
    Writeln(#9'Open <file name> and enter edit mode');
    Writeln('Usage: ' + AppName + ' -version');
    Writeln(#9'Print version and exit');
    Writeln('Usage: ' + AppName + ' -h');
    Writeln(#9'Print this usage and exit');
    Halt(0);
End;
Procedure ShowVersion;
Begin
    Writeln(AppName + ' ' + AppVersion);
    Halt(0);
End;
Procedure OpenForEdit(AFileName: String);

Var 
    FCmd:   String;
    FExit:   Boolean;
Begin
    Writeln('Open ' + AFileName);
    FExit := False;
    Repeat
        Write(': ');
        Readln(FCmd);
    Until (FExit);
End;
Begin
    ParseParam;
    If FlagShowUsage Then
        ShowUsage
    Else If FlagShowVersion Then
             ShowVersion
    Else
        Begin
            OpenForEdit(FileName);
        End;
End.
